<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="test"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <script type="text/babel">
        class A extends React.Component {
            state = {
                carName: '奔驰'
            }

            changeCar = () => {
                let { carName } = this.state
                this.setState({
                    carName: '奥拓'
                })
            }
            render() {
                return (
                    <div>
                        <h3>A组件</h3>
                        <B carName={this.state.carName} />
                        <button onClick={this.changeCar}>点击切换车辆</button>
                    </div>

                )
            }
        }
        class B extends React.Component {

            componentWillReceiveProps() {//只有在接收新的数据的时候才会调用
                console.log('componentWillReceiveProps');
            }
            render() {
                return (
                    <div>
                        <h3>B组件</h3>
                        <div>b组件收到的数据为{this.props.carName}</div>
                    </div>

                )
            }
        }

        ReactDOM.render(<A />, document.getElementById('test'))
    </script>
</body>

</html>